﻿using Beetle;
using System;
using System.Collections.Generic;

internal class Class_ag : IDisposable
{
    public static int _field_a;
    protected static List<Class_ag> _field_b = new List<Class_ag>();
    private static int _field_c = 0;
    private bool _field_d;
    private object _field_e;
    protected Queue<Class_b> _field_f;
    protected int _field_g;
    private bool _field_h;

    static Class_ag()
    {
        Class_ae.f();
    }

    public Class_ag(int A_0, int A_1)
    {
        this._field_e = new object();
        this._field_g = A_1;
        this._field_f = new Queue<Class_b>(A_0);
        for (int i = 0; i < A_0; i++)
        {
            this._field_f.Enqueue(this.a(A_1));
        }
    }

    public Class_ag(int A_0, int A_1, bool A_2)
    {
        this._field_e = new object();
        this._field_d = A_2;
        this._field_g = A_1;
        this._field_f = new Queue<Class_b>(A_0);
        for (int i = 0; i < A_0; i++)
        {
            this._field_f.Enqueue(this.a(A_1));
        }
    }

    private void a()
    {
        lock (this._field_e)
        {
            while (this._field_f.Count > 0)
            {
                this._field_f.Dequeue()._field_l = null;
            }
        }
    }

    public virtual void a(Class_b A_0)
    {
        lock (this._field_e)
        {
            this._field_f.Enqueue(A_0);
        }
    }

    protected Class_b a(int A_0)
    {
        Class_b _b;
        if (this._field_d)
        {
            _b = new Class_b(A_0, new Class_a());
        }
        else
        {
            _b = new Class_b(A_0);
        }
        _b._field_l = this;
        return _b;
    }

    public static void a(int A_0, int A_1)
    {
        a(A_0, A_1, TcpUtils.SendBufferLength);
    }

    public static void a(int A_0, int A_1, int A_2)
    {
        lock (_field_b)
        {
            for (int i = 0; i < A_0; i++)
            {
                _field_b.Add(new Class_ag(A_1, A_2));
            }
        }
    }

    public static Class_ag b()
    {
        lock (_field_b)
        {
            _field_c++;
            if (_field_c >= _field_b.Count)
            {
                _field_c = 0;
            }
            return _field_b[_field_c];
        }
    }

    public static IList<int> c()
    {
        List<int> list = new List<int>();
        for (int i = 0; i < _field_b.Count; i++)
        {
            list.Add(_field_b[i]._field_f.Count);
        }
        return list;
    }

    public static void d()
    {
        lock (_field_b)
        {
            for (int i = 0; i < _field_b.Count; i++)
            {
                _field_b[i].Dispose();
            }
            _field_b.Clear();
        }
    }

    public void Dispose()
    {
        lock (this)
        {
            if (!this._field_h)
            {
                this.a();
                this._field_h = true;
            }
        }
    }

    public void e()
    {
        foreach (Class_b _b in this._field_f)
        {
            _b.d();
        }
    }

    public int f()
    {
        return this._field_f.Count;
    }

    public virtual Class_b g()
    {
        lock (this._field_e)
        {
            Class_b _b = (this._field_f.Count > 0) ? this._field_f.Dequeue() : this.a(this._field_g);
            _b.a();
            return _b;
        }
    }
}

